﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;

namespace SCIMC.Site.Web
{
    /// <summary>
    /// Summary description for AutoComplete
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class AutoComplete : System.Web.Services.WebService
    {

        [WebMethod]
        public List<string> ProcessadorAutoComplete(string texto)
        {
            List<string> list = new List<string>();
            string sql = "SELECT Descricao FROM tbAutoCompleteProcessador where Descricao like '%" + texto + "%' and Ativo = 1;";
            string conexao = "Data Source=CLAUSIOBARBOSA\\SQLEXPRESS;Initial Catalog=GICMC_dataBase;Integrated Security=True;";
            using (SqlConnection connection = new SqlConnection(conexao))
            using (SqlCommand command = new SqlCommand(sql, connection))
            {
                connection.Open();

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        list.Add(reader[0].ToString());
                    }
                }
            }

            return list;
        }
    }
}
